package com.itheima.springbootwebtlias.mapper;

import com.itheima.springbootwebtlias.pojo.Dept;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * 部门持久层接口：处理部门相关的持久层操作
 */

@Mapper
public interface DeptMapper {

    //查询所有部门
    @Select("select * from dept")
    List<Dept> selectAll();

    //删除部门
    @Delete("delete from dept where id = #{id}")
    void removeById(Integer id);

    //保存部门(新增部门)
    @Insert("insert into dept (id, name, create_time, update_time) values (null,#{name},#{createTime},#{updateTime})")
    void saveDept(Dept dept);

    //根据id查询部门
    @Select("select * from dept where id = #{id}")
    Dept selectById(Integer id);

    //更新部门 ，也可在这里更新时间
    @Insert("update dept set name = #{name},update_time = #{updateTime} where id = #{id}")
    void update(Dept dept);

    //根据部门id查询部门员工数量,判断部门是否可以删除
    @Select("select count(*) from emp where dept_id = #{id}")
    Integer selectCountByDeptId(Integer id);
}
